class marker {
  constructor ({ id, gantt }) {
    this.gantt = gantt
  }

  getMarkData (id) {
    const ganttMarkerList = Array.from(document.getElementsByClassName('gantt_marker'))
    const node = ganttMarkerList.find(v => v.getAttribute('data-marker-id') === `${id}`)
    const data = this.gantt.getMarker(id)
    return {
      node,
      data
    }
  }

  deleteMarker (data) {
    for (let i = 0; i < data.length; i++) {
      const target = data[i]
      this.gantt.deleteMarker(target)
    }
  }

  updateStyle (target) {
    const theme = 'gantMarkTheme'
    const { style, css } = target
    const themeTalk = document.getElementById(theme)
    let styleContent = ''
    if (style) {
      if (themeTalk) {
        styleContent = themeTalk.innerText + `.${css} {${style}}`
      } else {
        styleContent = `.${css} {${style}}`
      }
      this.updateDomHeadStyle(theme, styleContent)
    }
  }

  updateDomHeadStyle (id, styleContent) {
    let styleTag = document.getElementById(id)
    if (!styleTag) {
      styleTag = document.createElement('style')
      styleTag.setAttribute('id', id)
      document.head.appendChild(styleTag)
    }
    styleTag.innerText = styleContent.replace(/@font-face{[^}]+}/, '')
  }
}
export default marker
